import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.14

Item {
    id:root
    implicitHeight: 80
    implicitWidth: fileIcon.width

    signal selected()

    property string  source : ""
    property alias   name : fileName.text
    property string  type : "dir"    //类型

    property var fileTypeMap : {
                                    "dir":"qrc:/imgs/dir.png",
                                    "jpg":"qrc:/imgs/pic.png",
                                    "unkonw":"qrc:/imgs/untype.png",
                                    "file":"qrc:/imgs/untype.png"
                                }

    Rectangle{
        id:fileBox
        anchors.fill: parent
        //color:"red"

        Image {
            id: fileIcon
            width: 65
            height: 65
            source:root.fileTypeMap[root.type]

            Connections{
                target: showImage
                function onCallQmlRefeshImg(){

                    if("dir" == root.type) return;

                    fileIcon.source = ""
                    fileIcon.source = "image://imageprovider/" + fileName.text
                    fileIcon.width = 60
                    fileIcon.height = 60
                }
            }
        }

        Text {
            id:fileName
            text: "unkown"
            font.pixelSize: 16
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 0 //"dir" === root.type ? -12 : -22
            anchors.horizontalCenter: parent.horizontalCenter
        }
    }

    MouseArea{
        anchors.fill: root
        onPressed: {
            fileIcon.scale *=1.1
        }
        onReleased: {
            fileIcon.scale /=1.1
            if("dir" == root.type){
                printControl.getNext_DirInfo(fileName.text);
            }else{
                root.selected();
            }
        }
    }
}
